package com.ruoyi.web.controller.system;


import com.ruoyi.web.service.C2VersionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/C2Versions")
public class C2VersionsController {

    @Autowired
    private C2VersionsService c2VersionsService;

    /**
     * 获取版本数据：计划版本数、释放版本数、发布版本数的 versionNo 集合
     *
     * @return 返回 versionNo 集合的 Map 数据
     */
    @GetMapping("/byStatus")
    public ResponseEntity<Map<String, String>> getVersionData() {
        try {
            // 调用 Service 层获取版本数据
            Map<String, String> versionData = c2VersionsService.getVersionData();

            // 判断是否有数据
            if (versionData == null || versionData.isEmpty()) {
                return ResponseEntity.status(HttpStatus.NO_CONTENT).body(versionData);
            }

            // 正常返回结果
            return ResponseEntity.ok(versionData);

        } catch (Exception e) {
            // 捕获异常并返回错误信息
            e.printStackTrace();
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body(Map.of("error", "Failed to fetch version data: " + e.getMessage()));
        }
    }
}